/*
 *  Project:            programmable_parser_v0.1.
 *  Module name:        L2_Switch.
 *  Description:        This module is used to switch pkt.
 *  Last updated date:  2023.02.24.
 *
 *  Copyright (C) 2023 Junnan Li <lijunnan@nudt.edu.cn>.
 *  Copyright and related rights are licensed under the MIT license.
 *
 *	Noted:
 *		1) i_tcam_conf: 
 *			[39:36] is reserved;
 *			[35:32] is type in num; 
 *			[31:16] type field; 
 *			[15:0] mask;
 *		2) i_sram_conf: 
 *			[7:0] is next type in num; [7:6] 2'b01 is head, 2'b10 is tail;
 *			[15:8] is offset for current protocol; 
 *			[11*i+5+16:11*i+16] field to extract; type field is i=0;
 *		3) default rule of sram:
 *			addr = 0 -> extract {dst/src MAC};
 */

module L2_Switch (
 	//* clk & reset;
	 input 	wire 				i_clk
	,input 	wire				i_rst_n  
	,input	wire [	   133:0]	i_data 
	,input 	wire 				i_data_valid
	,output reg 				o_data_valid
	,output reg  [	   133:0]	o_data
);

	//====================================================================//
	//*   internal reg/wire/param declarations
	//====================================================================//
	

	//====================================================================//
	//*   port_0 <--> port_1, port_2 <--> port_3;
	//====================================================================//
	always @(posedge i_clk or negedge i_rst_n) begin
		if(~i_rst_n) begin
			o_data_valid				<= 1'b0;
			o_data						<= 3'b0;
		end 
		else begin
			if(i_data_valid == 1'b1) begin
				o_data_valid			<= 1'b1;
				if(i_data[133:132] == 2'b01) begin
					o_data[133:132]		<= 2'b01;
					(*full_case, parallel_case*)
					case(i_data[129:128])
						2'd0: o_data[131:128]	<= 4'h2;
						2'd1: o_data[131:128]	<= 4'h1;
						2'd2: o_data[131:128]	<= 4'h8;
						2'd3: o_data[131:128]	<= 4'h4;
					endcase
					
					o_data[127:0]		<= i_data[127:0];
				end
				else begin
					o_data				<= i_data;
				end
			end
			else begin
				o_data_valid			<= 1'b0;
			end
		end
	end

	
endmodule    